/*
 * Copyright (C) 2011 Mette Bank, Rikke Jensen, Kenneth Brodersen, Thomas Pedersen
 * 
 * This file is part of digiPECS.
 * 
 * digiPECS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * digiPECS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with digiPECS.  If not, see <http://www.gnu.org/licenses/>.
 */

package sw6.digipecs.widget.admin;

import java.util.ArrayList;

import sw6.digipecs.exceptions.ImageIsEmptyException;
import sw6.digipecs.model.ExtImageInSentenceBoard;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class SelectLockedAdapter extends BaseAdapter {

	private Context mContext;
	private ArrayList<ExtImageInSentenceBoard> mImages;
	
	public SelectLockedAdapter(Context context, ArrayList<ExtImageInSentenceBoard> images)
	{
		mContext = context; 
		mImages = images; 	
	}
	
	@Override
	public int getCount() {
		return mImages.size(); 
	}

	@Override
	public Object getItem(int arg0) {
		return mImages.get(arg0); 
	}

	@Override
	public long getItemId(int arg0) {
		try {
			return (mImages.get(arg0)).getId();
		} catch (ImageIsEmptyException e) {
			return 0; 
		} 
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		SelectLockedItem returnView = null; 
		if(arg1==null)
			returnView=new SelectLockedItem(mContext); 
		else 
			returnView=(SelectLockedItem)arg1; 
		
		ExtImageInSentenceBoard image = mImages.get(arg0); 
		try {
			if(image.isLocked())
				returnView.setImgSrc(image.getUri());
		} catch (ImageIsEmptyException e) {
		} 
		//Laver tekst
		StringBuilder text = new StringBuilder(); 
		text.append("Plads "); 
		text.append(arg0+1); 
		if(!image.isLocked())
			text.append(" (Tom)");
		else
			try {
				text.append(image.getText());
			} catch (ImageIsEmptyException e) {
				e.printStackTrace();
			} 
		returnView.setText(text.toString()); 
		
		return returnView;
	}
}
